﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ArchitectureV2
{
    public class SessionID
    {
        private byte[] id;

        public byte[] ID { get { return (id); } }

        public SessionID(byte[] id) { this.id = id; }
        public SessionID(int n) { this.id = new byte[n]; }

        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is SessionID)) { return (false); }
            byte[] x = ((SessionID)obj).id;
            if (id == null || x == null) { return (false); }
            if (x.Length != id.Length) { return (false); }
            for (int i = 0; i < id.Length; i++) { if (x[i] != id[i]) { return (false); } }
            return (true);
        }

        public override int GetHashCode()
        {
            int h0 = 0, h1 = 0, h2 = 0;
            if (id != null) { foreach (byte b in id) { h0 += (int)b; h1 += h0; h2 += h1; } }
            return (h0 ^ h1 ^ h2);
        }
    }
}
